using UnityEngine;
using System.Collections;

public class ProcRockPool : MonoBehaviour
{
    public GameObject rock;

    private static ProcRockPool m_instance;

    private ArrayList listLivePool = new ArrayList();
    private ArrayList listDeadPool = new ArrayList();

    public static ProcRockPool Instance
    {
        get
        {
            return m_instance;
        }
    }

    public GameObject GetRock( Vector3 vPos, Quaternion qRot )
    {
        GameObject rockNew = null;

        if (listDeadPool.Count == 0)
        {
            rockNew = (GameObject)Instantiate(rock, vPos, qRot);
            //Debug.Log("Instantiate Rock");
        }
        else
        {
            rockNew = (GameObject)listDeadPool[0];
            rockNew.transform.position = vPos;
            rockNew.transform.rotation = qRot;
            rockNew.active = true;
            listDeadPool.RemoveAt(0);
            //Debug.Log("Get Rock from pool");
        }

        listLivePool.Add(rockNew);

        return rockNew;
    }

    public void DeadRock(GameObject rockDead)
    {
        listLivePool.Remove(rockDead);
        rockDead.active = false;
        listDeadPool.Add(rockDead);
    }

    void Start()
    {
        m_instance = this;

        for (int i = 0; i < 50; i++)
            listDeadPool.Add(Instantiate(rock));
    }

    void Update()
    {
    }
}